<?php
//商家中心入口文件
include_once('./common.inc.php');
InitGP('action'); //初始化變量全局返回
//檢測用戶是否登錄
$_SUSERS=array();
//允許的動作
$actarray = array('login','quit','bond','settings');
$action = (!empty($action) && in_array($action, $actarray))?$action:'login';
if ($action!="login") {
	scheckauth();//實時監測用戶是否登錄狀態
	schecklogin();//判斷是否登錄，沒登錄轉到登錄
}
//鏈接
$theurl = 's.php?action='.$action;

include_once(ROOT_PATH.'/suppliers/'.$action.'.php'); //調用相應處理文件



function scheckauth(){
	global $db,$tablepre,$_SUSERS;
	$loginauth=get_cookie('suppliersauth');
	if(empty($loginauth))$loginauth=$_POST['suppliersauth'];
	if(!empty($loginauth)) {
		@list($sid, $user,$pwd) = explode("\t", cookie_authcode($loginauth,'DECODE'));
		
		$_SUSERS['sid']=$sid;
		if(!empty($sid) && !empty($user) && !empty($pwd) && !empty($_SUSERS['sid'])){
			$row = $db->fetch_first("Select * From {$tablepre}suppliers where name = '{$user}' and pwd='{$pwd}'");//檢測數據庫
			if(is_array($row)){
				$_SUSERS['name']=$row['name'];
				$_SUSERS['web']=$row['web'];
				$_SUSERS['address']=$row['address'];
				$_SUSERS['map']=$row['map'];
				$_SUSERS['tel']=$row['tel'];
				$_SUSERS['operating_time']=$row['operating_time'];
				$_SUSERS['codebar']=$row['codebar'];
				$_SUSERS['resolution']=$row['resolution'];
				$_SUSERS['bus']=$row['bus'];
				$_SUSERS['brief']=$row['brief'];
				$_SUSERS['about']=$row['about'];
				$_SUSERS['pwd']=$row['pwd'];
				
			}else $_SUSERS=array();
		}else $_SUSERS=array();
	}else $_SUSERS=array();
}
//檢測用戶

//檢測登錄並且提示
function schecklogin(){
	global $_SUSERS;
	if(empty($_SUSERS['sid'])) {
		//set_cookie('_refer', rawurlencode($_SERVER['REQUEST_URI']));//設置登錄成功跳轉地址
		dheader("s.php");//php跳轉頁面
		exit;
	}
}


?>